package com.hqyj.purchase.service.impl;

import com.hqyj.purchase.mapper.PurchaseInfoMapper;
import com.hqyj.purchase.model.PurchaseInfo;
import com.hqyj.purchase.service.PurchaseService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author qianyexiuci
 * @date 2021/09/06 14:23
 */
@Service
public class PurchaseServiceImpl implements PurchaseService {
    @Autowired
    private  PurchaseInfoMapper purchaseInfoMapper;

    @Override
    public List<PurchaseInfo> queryAllPurchaseInfo() {
        List<PurchaseInfo> purchaseInfoList = purchaseInfoMapper.queryAllPurchaseInfo();
        return  purchaseInfoList;
    }


    @Override
    public int updatePurchase(PurchaseInfo purchaseInfo,String provider,int price) {
        Date date = new Date();
        purchaseInfo.setPurchaseOrderNo("hqyj"+purchaseInfo.getId());
        purchaseInfo.setProvider(provider);
        purchaseInfo.setTradePrice(String.valueOf(price));
        purchaseInfo.setPurchaseDate(date);
        purchaseInfo.setState("已采购");
        int rows =purchaseInfoMapper.updateByPrimaryKey(purchaseInfo);
        return rows;
    }


    @Override
    public int deletePurchase(int id) {
        int rows =purchaseInfoMapper.deleteByPrimaryKey(id);
        return rows;
    }

    @Override
    public PurchaseInfo queryPurchaseInfoById(int id) {
        PurchaseInfo purchaseInfo =purchaseInfoMapper.selectByPrimaryKey(id);
        return purchaseInfo;
    }

    @Override
    public void updatePurchase(PurchaseInfo purchaseInfo) {
        purchaseInfoMapper.updateByPrimaryKey(purchaseInfo);
    }

    @Override
    public void addPurchaseInfo(PurchaseInfo purchaseInfo) {
        purchaseInfoMapper.insertSelective(purchaseInfo);
    }

    @Override
    public ArrayList<PurchaseInfo> queryAllNotPurchase() {
        return purchaseInfoMapper.queryAllNotPurchase();
    }

}
